<template>
  <a-modal title='选择回款记录' :width='1000' :dialog-style="{ top: '10px' }" :visible='visible' :confirmLoading='loading' :footer='null' @ok='handleSubmit' @cancel='handleCancel'>
    <f-table ref='table' rowKey='paymentId' v-if='visible' 
             :showSelectInfo='false' 
             @dblclick='dblclick' 
             :columns='columns' 
             :multiple='multiple' 
             :showSetting='false' 
             :showMultipleBtn='false' 
             :showRadio='!multiple' 
             :operator='operator' 
             :params='queryParam' 
             :api='api.payment'
             handler='hyHuikuanSelectListHandler' 
             @onSelectChange='onSelectChange'>
      <span slot='action' slot-scope='text, record'>
         <template>
           <a @click='openPaymentOrderModal(record)'>明细</a>
        </template>
      </span>
    </f-table>
    <select-payment-order-modal ref='paymentOrderModal'></select-payment-order-modal>
  </a-modal>
</template>
<script>
import api from "../js/api"
import SelectPaymentOrderModal from "@/views/module/haiying/components/select_payment_order_modal"

export default {
  name: "SelectHkBalanceModal",
  props: {
    multiple: {
      type: Boolean,
      default: false
    }
  },
  data() {
    let operator = []
    return {
      refs: this.$refs,
      api: Object.assign(api, this.api),
      loading: false,
      visible: false,
      chaifenModal: false,
      selectedRowKeys: [],
      selectedRows: [],
      //列表初始化查询参数
      queryParam: {},
      formItem: {
        customBalanceId: null,
        amount: 0
      },
      // 表头
      columns: [
        {
          title: "单位名称",
          align: "left",
          ellipsis: true,
          width: "150px",
          dataIndex: "customName"
        },
        {
          title: "收款金额",
          align: "center",
          width: "80px",
          dataIndex: "amount"
        },
        {
          title: "剩余金额",
          align: "center",
          width: "80px",
          dataIndex: "surplusAmount"
        },
        {
          title: "收款日期",
          align: "center",
          width: "100px",
          dataIndex: "amountDate"
        },
        {
          title: "收款银行",
          align: "left",
          width: "100px",
          dataIndex: "bankName"
        },
        {
          title: "操作",
          align: "center",
          width: "60px",
          scopedSlots: { customRender: "action" }
        }
      ],
      operator: operator
    }
  },
  methods: {
    open(params) {
      this.queryParam = params
      this.visible = true
      this.selectedRowKeys = []
      this.selectedRows = []
    },
    close() {
      this.$emit("close")
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
    dblclick(record, event) {
      let selectedRowKeys = []
      let selectedRows = []
      let amount = record.surplusAmount
      if (amount > 0) {
        selectedRowKeys.push(record.paymentId)
        selectedRows.push(record)
        this.$emit("onSelectChange", selectedRowKeys, selectedRows, this.queryParam)
        this.close()
      }
    },
    //打开认款使用明细
    openPaymentOrderModal(record) {
      this.$refs.paymentOrderModal.open({
        paymentId: record.paymentId,
        amount: record.amount
      })
    },
    //确认
    handleSubmit() {
      this.$emit("onSelectChange", this.$refs.table.getSelectedRowKey(), this.$refs.table.getSelectedRows(), this.queryParam)
      this.close()
    },
    //回调
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    }
  },
  created() {
  },
  components: { SelectPaymentOrderModal }
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
